class Person
  include Mongoid::Document
  field :name,type:String
  embeds_one :address, as: :locatable 
  embeds_many :phones

  has_and_belongs_to_many :interests ## a person may have more than 1 interest

  validates_associated :address
  
  accepts_nested_attributes_for :phones, reject_if: :reject_phones
  accepts_nested_attributes_for :address , reject_if: proc { |attributes| attributes["street"].blank? }

  
    def reject_phones(attributed)
    attributed["number"].blank?
    end

  class << self  
    def get_members_in_egypt
   	Person.where('adress.country' => 'Egypt')

    end
  end
end
